var data = {
  isDiscoverying: false,
  isConnected: false,
  isNotifyOn: false,
  ble_device: null,
  foundDevices: [],
  isConnecting: false,
  service_uuid: "",
  char_uuid: "",
}

var private_data = {
  showDialogEnable: true,
  showDebugMsgEnable: true,
  msg_language: 'EN',
  startDiscovery_msg_cn: "正在搜寻蓝牙设备...",
  startDiscovery_msg_en: 'Searching...',
  warning_msg_cn: "警告",
  warning_msg_en: 'Warning',
  devFound_msg_cn: "找到设备:",
  devFound_msg_en: "Found device(s):",
  open_ble_adapter_failed_msg_cn: '请检查蓝牙是否打开并重试',
  open_ble_adapter_failed_msg_en: 'Please check bluetooth wether turn on and try again.',
  ble_device_error_msg_cn: '蓝牙设备异常',
  ble_device_error_msg_en: 'Bluetooth device error',
  ble_connecting_msg_cn: '正在连接...',
  ble_connecting_msg_en: 'Connecting...',
  ble_connect_failed_msg_cn: '连接失败',
  ble_connect_failed_msg_en: 'Connect failed',
  ble_already_connect_msg_cn: '蓝牙已连接!',
  ble_already_connect_msg_en: 'Connected!',
  // ble_disconneting_msg_cn: '正在断开连接...',
  ble_disconnect_msg_cn: '蓝牙已断开',
  ble_disconnect_msg_en: 'Disconnect',
  ble_disconenct_failed_cn: '蓝牙断连失败',
  ble_disconenct_failed_en: 'Disconnect failed',
  ble_not_connect_msg_cn: '蓝牙未连接',
  ble_not_connect_msg_en: 'Not connected',
}

function setShowDialogEnable(enable) {
  private_data.showDialogEnable = enable
}

function getShowDialogEnable() {
  return private_data.showDialogEnable
}

function setshowDebugMsgEnable(enable) {
  private_data.showDebugMsgEnable = enable
}

function getshowDebugMsgEnable() {
  return private_data.showDebugMsgEnable
} 

function ble_startDiscovery() {
  // var that = this
  wx.startBluetoothDevicesDiscovery({
    allowDuplicatesKey: false,

    success: function(res) {
      data.isDiscoverying = true
      data.foundDevices = []
      data.ble_device = null
      data.isConnected = false
      data.isNotifyOn = false
      if (private_data.msg_language == 'CN') {
        var startDiscovery_msg = private_data.startDiscovery_msg_cn
      } else {
        var startDiscovery_msg = private_data.startDiscovery_msg_en //+ "(" + (data.foundDevices.length) + ")"
      }
      if (private_data.showDialogEnable) {
        wx.showLoading({
          title: startDiscovery_msg,
        })
      }
    },
  })
}

function ble_failCallback(res) {

}

function ble_openAdaptorandStartDiscovery() {
  // var that = this
  wx.openBluetoothAdapter({
    success: function(res) {
      ble_startDiscovery()
      return true
    },
    fail: function(res) {
      if (private_data.showDialogEnable) {
        if(private_data.msg_language == 'CN') {
          var warning_title = private_data.warning_msg_cn
          var warning_content = private_data.open_ble_adapter_failed_msg_cn
        } else {
          var warning_title = private_data.warning_msg_en
          var warning_content = private_data.open_ble_adapter_failed_msg_en
        }
        wx.showModal({
          title: warning_title,
          content: warning_content,
          showCancel: false,
          success: function (res) {

          }
        })
        ble_failCallback(res)
      }
      return false
    }
  })
}

function ble_onAdapterStatesChanged() {
  wx.onBluetoothAdapterStateChange(function(res){
    if(!res.available) {
      if(private_data.showDebugMsgEnable) {
        console.log("BLE res not available")
      }
      ble_failCallback(res)
      
    }
  })
}

function ab2hex(buffer) {
  var hexArr = Array.prototype.map.call(
    new Uint8Array(buffer),
    function (bit) {
      return ('00' + bit.toString(16)).slice(-2)
    }
  )
  return hexArr.join('');
}

function ble_onDeviceFound(ble_FoundEndCheckCallback) {
  // var that = this
  wx.onBluetoothDeviceFound(function(res){
    let isNewDevice = true
    // If this is a single device result
    if (res.deviceId) {
      // Ergodic
      data.foundDevices.forEach(function (foundDev, index) {
        if (res.deviceId == foundDev.deviceId) {
          isNewDevice = false
        }
      })
      // If this is a new device
      if(isNewDevice) {
        data.foundDevices.push(res)
      }
    } else if(res.devices) {
      // Else if devices list
      data.foundDevices.forEach(function (foundDev, index) {
        if (res.devices[0].deviceId == foundDev.deviceId) {
          isNewDevice = false
        }
      })
      // If this is a new device
      if (isNewDevice) {
        data.foundDevices.push(res.devices[0])
      }
    } else if (res[0]) {
      // Ergodic
      data.foundDevices.forEach(function (foundDev, index) {
        if (res[0].deviceId == foundDev.deviceId) {
          newDevice = false
        }
      })
      // If this is a new device
      if (isNewDevice) {
        data.foundDevices.push(res[0])
      }
    }
    
    if (isNewDevice == true) {
      if (private_data.showDebugMsgEnable) {
        // console.log(data.foundDevices)
        // data.foundDevices.forEach(function(dev, index) {
        //   // console.log(ab2hex(dev.advertisData))
        //   // let find_mac = ab2hex(dev.advertisData)
        //   // // console.log(find_mac)
        //   // if (find_mac == "102000000062") {
        //   //   console.log("found")
        //   // } else {
        //   //   console.log("not found" + find_mac)
        //   // }
        // })
      }

      if (private_data.showDialogEnable) {
        wx.hideLoading()

        if (private_data.msg_language == 'CN') {
          var found_msg = private_data.devFound_msg_cn + data.foundDevices.length
        } else {
          var found_msg = private_data.devFound_msg_en + data.foundDevices.length
        }
        
        wx.showLoading({
          title: found_msg,
        })
      }

      if (ble_FoundEndCheckCallback) {
        ble_FoundEndCheckCallback()
      }
      
    }

  })
}

function ble_getDeviceinFoundDeviceListByName(ble_name) {
  var found_dev = null
  data.foundDevices.forEach(function (dev, index) {
    // console.log(dev)
    if(dev.name.length >= ble_name.length) {
      if (dev.name == ble_name || dev.name.substring(0, ble_name.length) == ble_name) {
        found_dev = dev
        data.ble_device = dev
        
      } 
    }
  })
  return found_dev
}

function ble_getDeviceinFoundDeviceListByDeviceID(dev_id) {
  var found_dev = null
  data.foundDevices.forEach(function (dev, index) {
    // console.log(dev)
    // if (dev.name.length >= ble_name.length) {
    //   if (dev.name == ble_name || dev.name.substring(0, ble_name.length) == ble_name) {
    //     found_dev = dev
    //     data.ble_device = dev

    //   }
    // }
    if(dev.deviceId == dev_id) {
      found_dev = dev
      data.ble_device = dev
    }
  })
  return found_dev
}

function ble_onConnectStateChange() {
  wx.onBLEConnectionStateChange(function(res){
    data.isConnected = res.connected
  })
}

function ble_connectToDevice(ble_connectCallback) {

  if(!data.isConnected) {
    if(data.ble_device == null) {
      if(private_data.showDebugMsgEnable) {
        console.log("ble device null error")
      }
      if(private_data.showDialogEnable) {
        if(private_data.msg_language == 'CN') {
          var toast_title = private_data.ble_device_error_msg_cn
        } else {
          var toast_title = private_data.ble_device_error_msg_en
        }
        wx.showToast({
          title: toast_title,
          icon: 'failed',
          showCancel: false
        })
      }
    } else {
      data.isNotifyOn = false
      // data.isConnected = true
      if (!data.isConnecting) {
        data.isConnecting = true
        if (private_data.showDialogEnable) {
          if(private_data.msg_language == 'CN') {
            var loading_title = private_data.ble_connecting_msg_cn
          } else {
            var loading_title = private_data.ble_connecting_msg_en
          }
          wx.showLoading({
            title: loading_title,
          })
        }
        wx.createBLEConnection({
          deviceId: data.ble_device.deviceId,
          success: function (res) {
            if (private_data.showDebugMsgEnable) {
              console.log("Connect success!")
            }

            if (private_data.showDialogEnable) {
              if(private_data.msg_language == 'CN') {
                var toast_title = private_data.ble_already_connect_msg_cn
              } else {
                var toast_title = private_data.ble_already_connect_msg_en
              }
              wx.showToast({
                title: toast_title,
                icon: 'success',
                duration: 1000,
                showCancel: false
              })

            }
            data.isConnected = true
            data.isConnecting = false
            if (ble_connectCallback) {
              ble_connectCallback()
            }

          },
          fail: function (res) {
            if (private_data.showDebugMsgEnable) {
              console.log("Connect failed")
            }
            if (private_data.showDialogEnable) {
              if(private_data.msg_language == 'CN') {
                var toast_title = private_data.ble_connect_failed_msg_cn
              } else {
                var toast_title = private_data.ble_connect_failed_msg_en
              }
              wx.showToast({
                title: toast_title,
                icon: 'failed',
                duration: 1000,
                showCancel: false
              })
            }
            data.isConnected = false
            data.isConnecting = false
            if (ble_connectCallback) {
              ble_connectCallback()
            }
          }
        })
      }
    }
    
  } else {
    if(private_data.showDebugMsgEnable) {
      console.log("Already connect")
    }
    if(private_data.showDialogEnable) {
      if(private_data.msg_language == 'CN') {
        var toast_title = private_data.ble_already_connect_msg_cn
      } else {
        var toast_title = private_data.ble_already_connect_msg_en
      }
      wx.showToast({
        title: toast_title,
        icon: 'failed',
        duration: 1000,
        showCancel: false
      })
    }
    if (ble_connectCallback) {
      ble_connectCallback()
    }
  }
}

function ble_stopDiscovery(ble_stopedDiscoveryCallback) {
  if(data.isDiscoverying) {
    data.isDiscoverying = false
    wx.stopBluetoothDevicesDiscovery({
      success: function(res) {
        

        if(private_data.showDebugMsgEnable) {
          console.log("Stop discovery success")
        }
        
        // Hide discovery dialog before
        if(private_data.showDialogEnable) {
          wx.hideLoading()
        }
        if (ble_stopedDiscoveryCallback) {
          ble_stopedDiscoveryCallback()
        }
        

        return true
      },
      fail: function(res) {
        data.isDiscoverying = true
        if(private_data.showDebugMsgEnable) {
          console.log("Stop discovery failed")
        }
        // if (ble_stopedDiscoveryCallback) {
        //   ble_stopedDiscoveryCallback()
        // }
      }
    })
  } else {
    // console.log("not discovery")
    // if (ble_stopedDiscoveryCallback) {
    //   ble_stopedDiscoveryCallback()
    // }
  }
  return false
}

function ble_disconnect(ble_disconnectCallback) {
  if(data.isConnected) {
    data.isConnected = false
    wx.closeBLEConnection({
      deviceId: data.ble_device.deviceId,
      success: function(res) {
        if(private_data.showDialogEnable) {
          if(private_data.msg_language == 'CN') {
            var toast_title = private_data.ble_disconnect_msg_cn
          } else {
            var toast_title = private_data.ble_disconnect_msg_en
          }
          wx.showToast({
            title: toast_title,
            icon: 'success',
            duration: 1000,
            showCancel: false
          })
        }
        if (ble_disconnectCallback) {
          ble_disconnectCallback()
        }
        data.isNotifyOn = false
        
      },
      fail: function(res) {
        ble_getDevice = true
        if (private_data.showDialogEnable) {
          if(private_data.msg_language == 'CN') {
            var toast_title = private_data.ble_disconenct_failed_cn
          } else {
            var toast_title = private_data.ble_disconenct_failed_en
          }
          wx.showToast({
            title: toast_title,
            icon: 'failed',
            duration: 1000,
            showCancel: false
          })
        }
        if (ble_disconnectCallback) {
          ble_disconnectCallback()
        }
      },
      
    })
  } else {
    if(private_data.showDebugMsgEnable) {
      console.log("ble not disconnect")
    }
    if (private_data.showDialogEnable) {
      if(private_data.msg_language == 'CN') {
        var toast_title = private_data.ble_not_connect_msg_cn
      } else {
        var toast_title = private_data.ble_not_connect_msg_en
      }
      wx.showToast({
        title: toast_title,
        icon: 'failed',
        duration: 1000,
        showCancel: false
      })
    }
    if (ble_disconnectCallback) {
      ble_disconnectCallback()
    }

  }
}

function ble_setDevice(dev) {
  data.ble_device = dev
}

function ble_getDevice() {
  return data.ble_device
}

function ble_turnOnNotify(service_uuid, char_uuid, ble_turnOnNotifyCallback) {
  if(data.isConnected) {
    wx.getBLEDeviceServices({
      deviceId: data.ble_device.deviceId,
      success: function(res) {
        res.services.forEach(function(service, index) {
          if(service.uuid == service_uuid) {
            // Find the service
            wx.getBLEDeviceCharacteristics({
              deviceId: data.ble_device.deviceId,
              serviceId: service.uuid,
              success: function(res) {
                res.characteristics.forEach(function(char, index) {
                  if(char.uuid == char_uuid) {
                    data.service_uuid = service.uuid
                    data.char_uuid = char.uuid
                    console.log(data.service_uuid + " " + data.char_uuid)
                    // Find the char
                    wx.notifyBLECharacteristicValueChange({
                      deviceId: data.ble_device.deviceId,
                      serviceId: service.uuid,
                      characteristicId: char.uuid,
                      state: true,
                      success: function(res) {
                        if(private_data.showDebugMsgEnable) {
                          console.log("Turn on notify success!!")
                          console.log("the success uuids are: " + data.service_uuid + " " + data.char_uuid)
                        }
                        data.isNotifyOn = true

                        if (ble_turnOnNotifyCallback) {
                          ble_turnOnNotifyCallback()
                        }
                      },
                      fail: function(res) {
                        if(private_data.showDebugMsgEnable) {
                          console.log("Turn on notify failed " + res)
                        }
                      }
                    })
                  }
                })
              },
            })
          }
        })
        if(private_data.showDebugMsgEnable) {
          console.log('uuids now are: ' + data.service_uuid + " " + data.char_uuid)
        }
      },
    })
  } else {
    if(private_data.showDebugMsgEnable) {
      console.log("BLE not connect")
    }
  }
}



function ble_getNotifyData(ble_getNotifyDataCallback) {
  wx.onBLECharacteristicValueChange(function(res){
    if (ble_getNotifyDataCallback) {
      ble_getNotifyDataCallback(res.value)
    }
  })
}

function ble_sendDataByUUIDs(service_uuid, char_uuid, sendData) {
  if(data.isConnected) {
    // var sendDataBuffer = new ArrayBuffer(sendData.length)
    // var unint8_sendDataBuffer = new Uint8Array(sendDataBuffer)
    // for (let i = 0; i < sendData.length; i++) {
    //   unint8_sendDataBuffer[i] = sendData.charCodeAt(i)
    // }
    // console.log("master send data is " + sendData)
    wx.writeBLECharacteristicValue({
      deviceId: data.ble_device.deviceId,
      serviceId: service_uuid,
      characteristicId: char_uuid,
      value: sendData,
      success: function (res) {
        if (private_data.showDebugMsgEnable) {
          // console.log("Send data success")
        }
      },
      fail: function (res) {
        if (private_data.showDebugMsgEnable) {
          console.log("Send data failed")
        }
      }
    })
  } else {
    if(private_data.showDebugMsgEnable) {
      console.log("ble not connect yet")
    }
  }
  
}

function ble_changeUUIDs(service_uuid, char_uuid, ble_changeUUIDsCallback) {
  if(data.isConnected) {
    console.log("find uuids")
    data.service_uuid = null,
    data.char_uuid = null,

    wx.getBLEDeviceServices({
      deviceId: data.ble_device.deviceId,
      success: function(res) {
        res.services.forEach(function(service, index) {
          if(service.uuid == service_uuid) {
            wx.getBLEDeviceCharacteristics({
              deviceId: data.ble_device.deviceId,
              serviceId: service.uuid,
              success: function(res) {
                res.characteristics.forEach(function(char, index) {
                  if(char.uuid == char_uuid) {
                    // Storage the value
                    data.service_uuid = service.uuid
                    data.char_uuid = char.uuid
                    if (ble_changeUUIDsCallback) {
                      ble_changeUUIDsCallback()
                    }
                  }
                })
              },
            })
          }
        })
      },
    })
  } else {
    if(private_data.showDebugMsgEnable) {
      console.log("ble not connect yet")
    }
  }
}

function ble_sendData(sendData) {
  if(!data.service_uuid || !data.char_uuid) {
    console.log(data.service_uuid + " " + data.char_uuid)
    if(private_data.showDebugMsgEnable) {
      console.log("uuids null")
    }
  } else {
    ble_sendDataByUUIDs(data.service_uuid, data.char_uuid, sendData)
  }
}

function getStringFromBuffer(buffer) {
  var arr = Array.prototype.map.call(new Uint8Array(buffer), x => x)
  var str = ''
  for (var i = 0; i < arr.length; i++) {
    str += String.fromCharCode(arr[i])
  }
  return str
}

function getCharsFromInt (int_data) {
  var int_datas = new ArrayBuffer(4)
  var int32 = new Int32Array(int_datas)
  int32[0] = int_data
  return int_datas
}

function getCharsFromFloat(float_data) {
  var int_datas = new ArrayBuffer(4)
  var f32 = new Float32Array(int_datas)
  f32[0] = float_data
  return int_datas
}

function getCharsFromString(str) {
  var chars = new ArrayBuffer(str.length)
  var uint8array_data = new Uint8Array(chars)
  for (let i = 0; i < str.length; i++) {
    uint8array_data[i] = str.charCodeAt(i)
  }
  return chars
}

function getCharFromNormalBuffer(buffer) {
  var chars = new ArrayBuffer(buffer.length)
  var uint8array_data = new Uint8Array(chars)
  for (let i = 0; i < buffer.length; i++) {
    uint8array_data[i] = buffer[i]
  }
  return chars
}

function connectTwoArrays(array1, array2) {
  var chars = new ArrayBuffer(array1.byteLength + array2.byteLength)
  var uint8array_data = new Uint8Array(chars)
  var uint8array_data_1 = new Uint8Array(array1)
  var uint8array_data_2 = new Uint8Array(array2)

  for (let i = 0; i < array1.byteLength; i++) {
    uint8array_data[i] = uint8array_data_1[i]
  }
  for(let i = 0; i < array2.byteLength ; i++) {
    uint8array_data[i + array1.byteLength] = uint8array_data_2[i]
  }
  return chars
}

function getIntFromString(string) {
  if (string.length != 4) {
    return
  } else {
    var int_array = new ArrayBuffer(4)

    var string_uchars = new Uint8Array(string.split('').map(function (c) {
      return c.charCodeAt(0)
    }))
    var array_uchars = new Uint8Array(int_array)

    array_uchars[0] = string_uchars[0]
    array_uchars[1] = string_uchars[1]
    array_uchars[2] = string_uchars[2]
    array_uchars[3] = string_uchars[3]

    var int_data = new Int32Array(int_array)

    return int_data[0]
  }
}

function getIntFromStringNew(string) {

    var int_array = new ArrayBuffer(string.length)

    var string_uchars = new Uint8Array(string.split('').map(function (c) {
      return c.charCodeAt(0)
    }))
    var array_uchars = new Uint8Array(int_array)

    for(let i = 0; i < string.length; i++) {
      array_uchars[i] = string_uchars[i]
    }

    if(string.length == 1) {
      var int_data = new Uint8Array(int_array)
    } else if(string.length == 4) {
      var int_data = new Int32Array(int_array)
    }   

    return int_data[0]
}

function getFloatFromString(string) {

  if(string.length == 4) {
    var int_array = new ArrayBuffer(string.length)

    var string_uchars = new Uint8Array(string.split('').map(function (c) {
      return c.charCodeAt(0)
    }))
    var array_uchars = new Uint8Array(int_array)
  
    for(let i = 0; i < string.length; i++) {
      array_uchars[i] = string_uchars[i]
    }

    var float_data = new Float32Array(int_array)

    console.log(float_data)
    console.log(int_array)
    return float_data[0]
  }

  return 0
}

function getIntFromBuffer(buffer) {
  var int_array = new ArrayBuffer(4)

  var array_uchars = new Uint8Array(int_array)
  var array_buffer = new Uint8Array(buffer)

  array_uchars[0] = array_buffer[0]
  array_uchars[1] = array_buffer[1]
  array_uchars[2] = array_buffer[2]
  array_uchars[3] = array_buffer[3]

  var int_data = new Int32Array(int_array)

  return int_data[0]
  
}

// Notification from Handle: 0x07 Value: b'f09a140000704e1800' 2020-11-19 17:35:30.522105
// 6.926410:9.331527:24.875000

function getFloatFromBuffer(buffer) {
  var int_array = new ArrayBuffer(4)

  var array_uchars = new Uint8Array(int_array)
  var array_buffer = new Uint8Array(buffer)

  array_uchars[0] = array_buffer[0]
  array_uchars[1] = array_buffer[1]
  array_uchars[2] = array_buffer[2]
  array_uchars[3] = array_buffer[3]

  // array_uchars[0] = 0xF0
  // array_uchars[1] = 0x9A
  // array_uchars[2] = 0x14
  // array_uchars[3] = 0x00

  // array_uchars[0] = 0x00
  // array_uchars[1] = 0x14
  // array_uchars[2] = 0x9A
  // array_uchars[3] = 0xF0

  console.log(int_array)

  var float_data = new Float32Array(int_array)

  return float_data[0]
  
}

function getStringFromInt(int_data) {
  var basic_arr = getCharsFromInt(int_data)
  var string = ""
  var i = new DataView(basic_arr)

  for (let s = 0; s < i.byteLength; s++) {
    string += String.fromCharCode(i.getUint8(s));
  }
  return string

}

function getStringFromFloat(float_data) {
  var basic_arr = getCharsFromFloat(float_data)
  var string = ""
  var i = new DataView(basic_arr)

  for (let s = 0; s < i.byteLength; s++) {
    string += String.fromCharCode(i.getUint8(s));
  }
  return string

}

function hmsArrary2Int(hms_array, time_zone) {

  if (hms_array[0] < time_zone) {
    var hour = hms_array[0] - time_zone + 24
  } else {
    hour = hms_array[0] - time_zone
  }

  let hms_int = hour * 3600 + hms_array[1] * 60 + hms_array[2]
  // console.log(hms_int)

  return hms_int
}

function hmsInt2Arrary(hms_int, time_zone) {
  hms_int = hms_int + 3600 * time_zone
  if (hms_int > 23 * 3600 + 59 * 60 + 59) {
    hms_int = hms_int - 24 * 3600
  }
  let hms_arrary = []
  hms_arrary.push(parseInt(hms_int / 3600))
  hms_int = hms_int - hms_arrary[0] * 3600
  hms_arrary.push(parseInt(hms_int / 60))
  hms_int = hms_int - hms_arrary[1] * 60
  hms_arrary.push(hms_int)

  return hms_arrary
}

function setLanguage2CN() {
  private_data.msg_language = 'CN'
}

function setLanguage2EN() {
  private_data.msg_language = 'EN'
}

module.exports = {
  data: data,

  setShowDialogEnable: setShowDialogEnable,
  getShowDialogEnable: getShowDialogEnable,
  setshowDebugMsgEnable: setshowDebugMsgEnable,
  getshowDebugMsgEnable: getshowDebugMsgEnable,
  ble_onAdapterStatesChanged: ble_onAdapterStatesChanged,
  ble_openAdaptorandStartDiscovery: ble_openAdaptorandStartDiscovery,
  ble_onDeviceFound: ble_onDeviceFound,
  ble_getDeviceinFoundDeviceListByName: ble_getDeviceinFoundDeviceListByName,
  ble_getDeviceinFoundDeviceListByDeviceID: ble_getDeviceinFoundDeviceListByDeviceID,
  ble_connectToDevice: ble_connectToDevice,
  ble_stopDiscovery: ble_stopDiscovery,
  ble_setDevice: ble_setDevice,
  ble_getDevice: ble_getDevice,
  ble_disconnect: ble_disconnect,
  ble_turnOnNotify: ble_turnOnNotify,
  ble_getNotifyData: ble_getNotifyData,
  ble_sendDataByUUIDs: ble_sendDataByUUIDs,
  ble_changeUUIDs: ble_changeUUIDs,
  ble_sendData: ble_sendData,

  getStringFromBuffer: getStringFromBuffer,
  getCharsFromInt: getCharsFromInt,
  getCharsFromFloat: getCharsFromFloat,
  getCharsFromString: getCharsFromString,
  getStringFromInt: getStringFromInt,
  getStringFromFloat: getStringFromFloat,
  getIntFromString: getIntFromString,
  getIntFromStringNew: getIntFromStringNew,
  getCharFromNormalBuffer: getCharFromNormalBuffer,
  connectTwoArrays: connectTwoArrays,
  getIntFromBuffer: getIntFromBuffer,
  getFloatFromString: getFloatFromString,
  getFloatFromBuffer: getFloatFromBuffer,


  hmsArrary2Int: hmsArrary2Int,
  hmsInt2Arrary: hmsInt2Arrary,

  setLanguage2CN: setLanguage2CN,
  setLanguage2EN: setLanguage2EN
}